package com.example.demo;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.HashMap;
import java.util.Map;

@RunWith(SpringRunner.class)
@SpringBootTest
public class OpForHash {
    @Autowired
    RedisTemplate redisTemplate;
    @Test
    public void hash1(){
        Map<String,Object> testMap=new HashMap();
        testMap.put("name","lixingzhen");
        testMap.put("age","22");
        redisTemplate.opsForHash().putAll("Hash",testMap);
        System.out.println(redisTemplate.opsForHash().entries("Hash"));
    }
    @Test
    public void hash2(){
        redisTemplate.opsForHash().put("redishash","name","lixingzhen2");
        redisTemplate.opsForHash().put("redishash","age","22.2");
        System.out.println(redisTemplate.opsForHash().entries("redishash"));
        System.out.println(redisTemplate.opsForHash().values("redishash"));
    }
    @Test
    public void delete(){
        redisTemplate.opsForHash().put("redishash","name","lixingzhen2");
        redisTemplate.opsForHash().put("redishash","age","22.2");
        System.out.println(redisTemplate.opsForHash().delete("redishash","name"));
        System.out.println(redisTemplate.opsForHash().entries("redishash"));
    }
    @Test
    public void hash4(){
        redisTemplate.opsForHash().put("redishash","name","lixingzhen2");
        redisTemplate.opsForHash().put("redishash","age","22.2");
        System.out.println(redisTemplate.opsForHash().hasKey("redishash","name"));
        System.out.println(redisTemplate.opsForHash().hasKey("redishash","age"));
        System.out.println(redisTemplate.opsForHash().hasKey("redishash","sex"));

    }
    @Test
    public void hash7(){
        redisTemplate.opsForHash().put("redishash","name","lixingzhen2");
        redisTemplate.opsForHash().put("redishash","age","22.2");
        System.out.println(redisTemplate.opsForHash().get("redishash","name"));

    }
    @Test
    public void hash8(){
        redisTemplate.opsForHash().put("redishash","name","lixingzhen2");
        redisTemplate.opsForHash().put("redishash","age","22.2");
        System.out.println(redisTemplate.opsForHash().keys("redishash"));
    }
    @Test
    public void hash9(){
        redisTemplate.opsForHash().put("redishash","name","lixingzhen2");
        redisTemplate.opsForHash().put("redishash","age","22.2");
        redisTemplate.opsForHash().put("redishash","sex","female");
        System.out.println(redisTemplate.opsForHash().size("redishash"));
    }

}
